from selenium.webdriver.common.by import By
from page.base_page import BasePage


class EmailSettingsPage(BasePage):
    # 邮件设置页面的路径
    url = "/index.php?m=setting&a=smtp"  #

    # 元素定位器
    email_setting_link_locator = (By.CSS_SELECTOR, "body > div.container > div.page-header > ul > li:nth-child(2) > a")
    set_now_link_locator = (By.LINK_TEXT, "点此设置")
    email_input_locator = (By.NAME, "address")
    save_btn_locator = (By.CSS_SELECTOR,
                        "body > div.container > div.tabbable > div > form > table > tbody > tr:nth-child(14) > td:nth-child(2) > input")
    tips_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-error")
    # 操作方法
    def click_email_setting_link(self):
        """点击邮件设置链接"""
        self.find_element(self.email_setting_link_locator).click()

    def click_set_now_link(self):
        """点击"点此设置"链接"""
        self.find_element(self.set_now_link_locator).click()

    def input_email_address(self, email):
        """输入邮件地址"""
        self.find_element(self.email_input_locator).send_keys(email)

    def click_save_button(self):
        """点击保存按钮"""
        self.find_element(self.save_btn_locator).click()

    def get_tips(self):
        """获取tips"""
        return self.find_element(self.tips_locator).text
